﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading;
//using Microsoft.Ccr.Core;
//using Microsoft.Ccr.Core.Arbiters;
//using NUnit.Framework;
//using XcoAppSpaces.Core.CcrWiring;
//using XcoAppSpaces.Core;
//using XcoAppSpaces.Core.CcrWiring.CcrRemote;
//using XcoAppSpaces.Contracts.Messaging;

//namespace test.XcoAppSpaces.Core.CcrWiring
//{
//	[TestFixture]
//	public class testNamedRemotableTask
//	{
//		[Test]
//		public void TestPostSequential()
//		{
//			int receivedCount = 0;
//			//RemoteMessage receivedData = null;

//			var port = new Port<int>();
//			var task = new NamedRemotableTask((msg => { Assert.AreEqual(receivedCount, msg.Data.Msg);
//															receivedCount++; 
//				//receivedData = msg.Data; 
//			}),
//															"testaddr", "testservice", "testworkerId", Guid.NewGuid(), port, MessageTransferMode.Sequential);
//			var dpq = new DispatcherQueue("test");
//			Arbiter.Activate(dpq, new Receiver(false, port, task));
			
//			int postCount = 10;
//			for (int i = 0; i < postCount; i++)
//				port.Post(i);
//			Thread.Sleep(500);

//			Assert.AreEqual(postCount, receivedCount);
//			//Console.WriteLine(((WorkerMessage)receivedData).SessionID);
//		}

//		[Test]
//		public void TestPostSequential2()
//		{
//			int receivedCount = 0;
//			var port = new Port<int>();
//			var task = new NamedRemotableTask((msg =>
//			{
//				Assert.AreEqual(receivedCount, msg.Data.Msg);
//				receivedCount++;
//			}),
//															"testaddr", "testservice", "testworkerId", Guid.NewGuid(), port, MessageTransferMode.Sequential);
//			var dpq = new DispatcherQueue("test");
//			port.ReceiveWithRemotableTask(dpq, task);

//			int postCount = 10;
//			for (int i = 0; i < postCount; i++)
//				port.Post(i);
//			Thread.Sleep(200);

//			Assert.AreEqual(postCount, receivedCount);
//		}

//		[Test]
//		public void TestPostParallel()
//		{
//			int receivedCount = 0;
//			var port = new Port<int>();
//			var task = new NamedRemotableTask((msg => { Interlocked.Increment(ref receivedCount); Console.WriteLine(msg.Data); }), "testaddr", "testservice", "testworkerId", Guid.NewGuid(), port, MessageTransferMode.Sequential);
//			var dpq = new DispatcherQueue("test");
//			Arbiter.Activate(dpq, new Receiver(true, port, task));
			
//			int postCount = 10;
//			for (int i = 0; i < postCount; i++)
//				port.Post(i);
//			Thread.Sleep(200);

//			Assert.AreEqual(postCount, receivedCount);
//		}
//	}
//}
